package net.alteiar.ui.algorithms;

import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;

import javax.swing.JLabel;
import javax.swing.JSpinner;
import javax.swing.SpinnerNumberModel;

public class PanelAlgorithmEdgeDetectorSobel extends
		PanelAlgorithmsDetails<AlgorithmEdgeDetectorSobel> {
	private static final long serialVersionUID = 1L;

	private final JSpinner spinnerLowThreshold;

	public PanelAlgorithmEdgeDetectorSobel() {
		super(new AlgorithmEdgeDetectorSobel());
		GridBagLayout gridBagLayout = new GridBagLayout();
		gridBagLayout.columnWidths = new int[] { 68, 56, 29, 0 };
		gridBagLayout.rowHeights = new int[] { 30, 0, 0, 0, 0, 0 };
		gridBagLayout.columnWeights = new double[] { 0.0, 0.0, 1.0,
				Double.MIN_VALUE };
		gridBagLayout.rowWeights = new double[] { 0.0, 0.0, 0.0, 0.0, 0.0,
				Double.MIN_VALUE };
		setLayout(gridBagLayout);

		JLabel lblLowThreshold = new JLabel("threshold:");
		GridBagConstraints gbc_lblLowThreshold = new GridBagConstraints();
		gbc_lblLowThreshold.anchor = GridBagConstraints.EAST;
		gbc_lblLowThreshold.insets = new Insets(0, 0, 5, 5);
		gbc_lblLowThreshold.gridx = 0;
		gbc_lblLowThreshold.gridy = 0;
		add(lblLowThreshold, gbc_lblLowThreshold);

		spinnerLowThreshold = new JSpinner();
		spinnerLowThreshold.setModel(new SpinnerNumberModel(5, 1, null, 1));
		GridBagConstraints gbc_spinnerLow;
		gbc_spinnerLow = new GridBagConstraints();
		gbc_spinnerLow.fill = GridBagConstraints.HORIZONTAL;
		gbc_spinnerLow.insets = new Insets(0, 0, 5, 5);
		gbc_spinnerLow.gridx = 1;
		gbc_spinnerLow.gridy = 0;
		add(spinnerLowThreshold, gbc_spinnerLow);
	}

	@Override
	protected void updateParams() {
		AlgorithmEdgeDetectorSobel algo = getAlgorithm();

		algo.setThreshold((int) spinnerLowThreshold.getValue());
	}

}
